import com.mysql.cj.jdbc.MysqlDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo2 {
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要输出的学生的学号");
        int id = scanner.nextInt();
        MysqlDataSource mysqlDataSource = new MysqlDataSource();
        mysqlDataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8");
        mysqlDataSource.setUser("root");
        mysqlDataSource.setPassword("354684");

        Connection connection = mysqlDataSource.getConnection();

        String sql = "delete from student where id=?";//增删查改同理
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1, id);

        int i = statement.executeUpdate();
        System.out.println("i = "+i);

        statement.close();
        connection.close();
    }
}
